﻿using System;
using System.ComponentModel;
using System.Data.Linq;
using System.Data.Linq.Mapping;

namespace Data.MappingClasses
{
    [TableAttribute(Name = "dbo.Month")]
    public partial class Month : INotifyPropertyChanging, INotifyPropertyChanged
    {

        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

        private short _idMonth;

        private string _nameMonth;

        private short _numberMonth;

        private EntitySet<Payment> _Payments;

        #region Extensibility Method Definitions
        partial void OnLoaded();
        partial void OnValidate(System.Data.Linq.ChangeAction action);
        partial void OnCreated();
        partial void OnidMonthChanging(short value);
        partial void OnidMonthChanged();
        partial void OnnameMonthChanging(string value);
        partial void OnnameMonthChanged();
        #endregion

        public Month()
        {
            this._Payments = new EntitySet<Payment>(new Action<Payment>(this.AttachPayments), new Action<Payment>(this.DetachPayments));
            OnCreated();
        }

        [ColumnAttribute(Storage = "_idMonth", AutoSync = AutoSync.OnInsert, DbType = "SmallInt NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)]
        public short idMonth
        {
            get
            {
                return this._idMonth;
            }
            set
            {
                if ((this._idMonth != value))
                {
                    this.OnidMonthChanging(value);
                    this.SendPropertyChanging();
                    this._idMonth = value;
                    this.SendPropertyChanged("idMonth");
                    this.OnidMonthChanged();
                }
            }
        }

        [ColumnAttribute(Storage = "_nameMonth", DbType = "VarChar(50) NOT NULL", CanBeNull = false)]
        public string nameMonth
        {
            get
            {
                return this._nameMonth;
            }
            set
            {
                if ((this._nameMonth != value))
                {
                    this.OnnameMonthChanging(value);
                    this.SendPropertyChanging();
                    this._nameMonth = value;
                    this.SendPropertyChanged("nameMonth");
                    this.OnnameMonthChanged();
                }
            }
        }

        [ColumnAttribute(Storage = "_numberMonth", DbType = "smallint NOT NULL", CanBeNull = false)]
        public short numberMonth
        {
            get { return _numberMonth; }
            set
            {
                if(_numberMonth != value)
                {
                    SendPropertyChanging();
                    _numberMonth = value;
                    SendPropertyChanged("numberMonth");
                }
            }
        }

        [AssociationAttribute(Name = "Month_Payment", Storage = "_Payments", ThisKey = "idMonth", OtherKey = "refMonth")]
        public EntitySet<Payment> Payments
        {
            get
            {
                return this._Payments;
            }
            set
            {
                this._Payments.Assign(value);
            }
        }

        public event PropertyChangingEventHandler PropertyChanging;

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void SendPropertyChanging()
        {
            if ((this.PropertyChanging != null))
            {
                this.PropertyChanging(this, emptyChangingEventArgs);
            }
        }

        protected virtual void SendPropertyChanged(String propertyName)
        {
            if ((this.PropertyChanged != null))
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        private void AttachPayments(Payment entity)
        {
            this.SendPropertyChanging();
            entity.Month = this;
        }

        private void DetachPayments(Payment entity)
        {
            this.SendPropertyChanging();
            entity.Month = null;
        }
    }
}